<template>
  <!-- 班级保育员工日检表 -->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="年月">
              <a-month-picker value-format="YYYY-MM" :disabled-date="disabledDate" style="width:100%;" v-model="queryParam.recordDate" placeholder="请选择年月" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="班级">
              <!-- <j-dict-select-tag type="list" v-model="queryParam.className"  dictCode="sk_class,class_name,id,del_flag = 0 order by sort_no asc" placeholder="请选择班级" /> -->
              <a-select  v-model="queryParam.classId" placeholder="请选择班级">
                <a-select-option :value="item.id" v-for="item in classList" :key="item.id">
                  {{ item.className }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('班级保育员工日检表')">导出</a-button> -->
      <!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <!-- <a  @click="handleExportXls('班级保育员工日检表',record)">导出</a> -->
          <a  @click="handleExport(record)">导出</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => deleteList(record)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <tb-child-care-check-table-modal ref="modalForm" @ok="modalFormOk"></tb-child-care-check-table-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import TbChildCareCheckTableModal from './modules/TbChildCareCheckTableModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { skClassList } from "@/api/management.js";
  import moment from 'moment';
  import { deleteAction } from '@/api/manage'
 
  export default {
    name: 'TbChildCareCheckTableList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      TbChildCareCheckTableModal
    },
    data () {
      return {
        description: '班级保育员工日检表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'班级',
            align:"center",
            dataIndex: 'className'
          },
          {
            title:'日期',
            align:"center",
            dataIndex: 'recordDate'
          },
          {
            title:'操作',
            align:"center",
            dataIndex: 'action',
            width:130,
            scopedSlots: { customRender: 'action' }
          },
          
        ],
        url: {
          list: "/table/tbChildCareCheckTable/page",
          delete: "/table/tbChildCareCheckTable/delete",
          deleteBatch: "/table/tbChildCareCheckTable/deleteBatch",
          exportXlsUrl: "/table/tbChildCareCheckTable/exportXls",
          importExcelUrl: "table/tbChildCareCheckTable/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
        classList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    this.getClassList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleExport(record){
        this.queryParam.classId = record.classId;
        this.queryParam.recordDate = record.recordDate
        this.handleExportXls('班级保育员工日检表')
      },
      getClassList(){
        skClassList().then((res)=>{
          if(res.success){
            this.classList = res.result;
          } else {
            this.$message.warning(res.message);
          }
        }).catch((error)=>{
          console.error(error);
        })
      },
      deleteList(record){
        let params = {
          id:record.id,
          classId:record.classId,
          recordDate:record.recordDate,
        }
        deleteAction(this.url.delete, params).then((res) => {
          if (res.success) {
            //重新计算分页问题
            this.reCalculatePage(1)
            this.$message.success(res.message);
            this.loadData();
          } else {
            this.$message.warning(res.message);
          }
        });
      },
      // 禁用选择日期
      moment,
      disabledDate(current) {
        let d = new Date();
        let M = d.getMonth() + 1;
        return current < moment().add(-M, 'month')
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'recordDate',text:'年月',dictCode:''})
        fieldList.push({type:'string',value:'className',text:'班级',dictCode:"sk_class,class_name,id"})
        fieldList.push({type:'string',value:'checkNode',text:'检查环节',dictCode:''})
        fieldList.push({type:'string',value:'checkContent',text:'检查标注',dictCode:''})
        fieldList.push({type:'string',value:'day1',text:'1日',dictCode:''})
        fieldList.push({type:'string',value:'day2',text:'2日',dictCode:''})
        fieldList.push({type:'string',value:'day3',text:'3日',dictCode:''})
        fieldList.push({type:'string',value:'day4',text:'4日',dictCode:''})
        fieldList.push({type:'string',value:'day5',text:'5日',dictCode:''})
        fieldList.push({type:'string',value:'day6',text:'6日',dictCode:''})
        fieldList.push({type:'string',value:'day7',text:'7日',dictCode:''})
        fieldList.push({type:'string',value:'day8',text:'8日',dictCode:''})
        fieldList.push({type:'string',value:'day9',text:'9日',dictCode:''})
        fieldList.push({type:'string',value:'day10',text:'10日',dictCode:''})
        fieldList.push({type:'string',value:'day11',text:'11日',dictCode:''})
        fieldList.push({type:'string',value:'day12',text:'12日',dictCode:''})
        fieldList.push({type:'string',value:'day13',text:'13日',dictCode:''})
        fieldList.push({type:'string',value:'day14',text:'14日',dictCode:''})
        fieldList.push({type:'string',value:'day15',text:'15日',dictCode:''})
        fieldList.push({type:'string',value:'day16',text:'16日',dictCode:''})
        fieldList.push({type:'string',value:'day17',text:'17日',dictCode:''})
        fieldList.push({type:'string',value:'day18',text:'18日',dictCode:''})
        fieldList.push({type:'string',value:'day19',text:'19日',dictCode:''})
        fieldList.push({type:'string',value:'day20',text:'20日',dictCode:''})
        fieldList.push({type:'string',value:'day21',text:'21日',dictCode:''})
        fieldList.push({type:'string',value:'day22',text:'22日',dictCode:''})
        fieldList.push({type:'string',value:'day23',text:'23日',dictCode:''})
        fieldList.push({type:'string',value:'day24',text:'24日',dictCode:''})
        fieldList.push({type:'string',value:'day25',text:'25日',dictCode:''})
        fieldList.push({type:'string',value:'day26',text:'26日',dictCode:''})
        fieldList.push({type:'string',value:'day27',text:'27日',dictCode:''})
        fieldList.push({type:'string',value:'day28',text:'28日',dictCode:''})
        fieldList.push({type:'string',value:'day29',text:'29日',dictCode:''})
        fieldList.push({type:'string',value:'day30',text:'30日',dictCode:''})
        fieldList.push({type:'string',value:'day31',text:'31日',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>